package nc.yonyou.common.util;

import nc.bs.dao.BaseDAO;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.vo.bd.defdoc.DefdocVO;
import nc.vo.pub.BusinessException;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class DefConfigUtils {

    public Map<String, String> getItfJDConfig() throws BusinessException {
        String configSql = " select b.* from bd_defdoclist a inner join bd_defdoc b on a.pk_defdoclist = b.pk_defdoclist " +
                " where a.dr = 0 and b.dr = 0 and b.enablestate = 2 and a.code = 'JD_CONFIG'";
        List<DefdocVO> defdocVOs = (List<DefdocVO>) new BaseDAO().executeQuery(configSql, new BeanListProcessor(DefdocVO.class));
        if (defdocVOs == null || defdocVOs.size() == 0) {
            throw new RuntimeException("defdoc[JD_CONFIG] is empty!");
        }
        Map<String, String> configMap = defdocVOs.stream().collect(Collectors.toMap(DefdocVO::getCode, DefdocVO::getName));
        return configMap;
    }

}
